package com.etrans.web.gps.business.system.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.etrans.web.gps.base.service.BaseService;
import com.etrans.web.gps.business.system.domain.ModuleVO;

@Service
public class ModuleService extends BaseService{

	@Transactional(readOnly = false, rollbackFor = {DataAccessException.class,Exception.class})
	public void save(ModuleVO form) {
		this.insert("moduleMapper.save",form);
	}
	
	@Transactional(readOnly = false, rollbackFor = {DataAccessException.class,Exception.class})
	public void update(ModuleVO form) {
		HashMap<String, Object> param = new HashMap<>();
		param.put("parentFuncId", form.getFunctionId());
		if ("DISABLED".equals(form.getState())) {
			param.put("state", "DISABLED");
		}else {
			param.put("state", "ENABLED");
		}
		this.update("moduleMapper.updateStateByParentId",param);
		this.update("moduleMapper.update",form);
	}
	
	@Transactional(readOnly = false, rollbackFor = {DataAccessException.class,Exception.class})
	public void delete(String id) {
		this.delete("moduleMapper.delete",id);
	}
	
	public ModuleVO queryById(String id) {
		return (ModuleVO)selectOne("moduleQuery.queryById",id);
	}
	
	public List<Map<String,Object>> queryAll(Map<String, Object> param){
		return selectList("moduleQuery.queryAll",param);
	}
	
	public List<Map<String,Object>> queryAllUser(Map<String, Object> param){
		return selectList("moduleQuery.queryAllUser",param);
	}
	
}
